<?php

/**
 * Created by PhpStorm.
 * User: steven
 * Date: 2016/4/20
 * Time: 22:59
 */
class HttpPost
{
    protected $CI;

    // We'll use a constructor, as you can't directly call a function
    // from a property definition.
    public function __construct()
    {
        // Assign the CodeIgniter super-object
        $this->CI =& get_instance();
    }
    public static function get_url_html($url){

        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
        $dxycontent = curl_exec($ch);
        return $dxycontent;
    }

    public static function post($url, $post_data = '', $timeout = 5){//curl

        $ch = curl_init();

        curl_setopt ($ch, CURLOPT_URL, $url);

        curl_setopt ($ch, CURLOPT_POST, 1);

        if($post_data != ''){
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        }

        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);


//        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);


        $file_contents = curl_exec($ch);

        curl_close($ch);

        return $file_contents;

    }

    public static function filter_url($source,$reg_tag){
        $result = preg_match_all($reg_tag,$source,$match_result);
        if($result) {
            return $match_result[1];
        }else{
            return false;
        }
    }
}